/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Util;

import objectreader.test.TestMultipleModelViewer;

/**
 *
 * @author Eduardo
 */
public class AnimacaoPeca implements TimerListener
{
    int xInicial, yInicial, xFinal, yFinal;
    double incX, incY, incZ, div, cont;
    long millis;
    TestMultipleModelViewer tela;
    Timer timer;

    public AnimacaoPeca (int xInicial, int yInicial, int xFinal, int yFinal, long millis, TestMultipleModelViewer tela)
    {
        this.cont = 0.0;
        this.div = 50;
        this.xInicial = xInicial;
        this.xFinal = xFinal;
        this.yInicial = yInicial;
        this.yFinal = yFinal;
        incX = (yFinal - yInicial) / div;
        incY = 0.1;
        incZ = (xInicial - xFinal) / div;
        this.tela = tela;
        this.tela.movX = 0.0;
        this.tela.movY = 0.0;
        this.tela.movZ = 0.0;
        timer = new Timer(this,millis);
    }

    public void movimentar ()
    {
        timer.start();
    }


    public void update(long millis)
    {
        if (cont == div - 1.0)
        {
            timer.finalizar();
            tela.pecaSendoMovida = -2;
            tela.tabuleiro[xFinal][yFinal] = tela.tabuleiro[xInicial][yInicial];
            tela.tabuleiro[xInicial][yInicial] = -1;
            tela.repaint();
            tela.mudaVez();
        }
        else
        {
            if (cont == div/2)
            {
                incY = -1 * incY;
            }
            tela.movX += incX;
            tela.movZ += incZ;
            tela.movY += incY;
            cont += 1.0;
            tela.repaint();
        }
    }
}
